<?php

namespace App\Module\Admin\Controllers;

use App\System\Cms\Repositories\CmsArticleRepository;
use App\System\Cms\Repositories\CmsTopicAlbumRepository;
use App\System\Cms\Repositories\CmsTopicRepository;
use Illuminate\Http\Request;

/**
 * Class ArticleController 文章管理
 * @package App\Module\Admin\Controllers
 */
class ArticleController extends Controller
{
    /**
     * 文章管理
     */

    //文章管理
    public function index(Request $request)
    {
        $article = CmsArticleRepository::getInstance();
        $data = $article->getArtilesDetil(1);
        return view('admin.article.index',compact('data'));
    }


    //保存
    public function ajaxSave(Request $request)
    {
        if ($request->isMethod('post')) {
            $thepost = $request->only('id', 'content');
            $id = $thepost['id'];
            $updata['content'] = $thepost['content'];
            $article = CmsArticleRepository::getInstance();
            $res = $article->saveArticle($id, $updata);
            $msg = $res['message'] ?? '操作失败';
            $state = !empty($res['data']) ? 'SUCCESS' : 'FAIL';
            $url = !empty($res['data']) ? url('/admin/article') : '';
            return response()->json(['message' => $msg, 'status' => $state, 'url' => $url]);
        }
    }
}
